<?php

namespace app\beautiful\logic;



use app\common\model\account\AccountModel;

use app\beautiful\model\logs\ApplyLogsModel;

use app\beautiful\model\StaffModel;



class ApplyServiceLogic{



    public static function apply($shop_id,$member_id,$source,$name,$service_id,$price,$market_price,$operate_type,$operate_id)

    {

        $apply_logs_model=new ApplyLogsModel();

        $apply_logs_model->shop_id=$shop_id;

        $apply_logs_model->member_id=$member_id;

        $apply_logs_model->source=$source;

        $apply_logs_model->name=$name;

        $apply_logs_model->service_id=$service_id;

        $apply_logs_model->price=$price;

        $apply_logs_model->market_price=$market_price;

        $apply_logs_model->operate_type=$operate_type;

        $apply_logs_model->operate_id=$operate_id;

        if($operate_type==1){

            if(null === $operator = StaffModel::find($operate_id)){

                return false;

            }

            $apply_logs_model->operate_mobile=$operator->mobile;

            $apply_logs_model->operate_name=$operator->name;

        }



        if($operate_type==2){

            if(null === $operator = AccountModel::find($operate_id)){

                return false;

            }



            $apply_logs_model->operate_mobile=$operator->mobile;

            $apply_logs_model->operate_name=$operator->username;

        }

        $apply_logs_model->save();

        return true;

    }



}

